package calculatorView;

import java.util.Observable;
import java.util.Observer;

import javax.swing.JTextArea;

import calculatorModel.Operation;

public class CalculatorArea  implements Observer {

	private Operation operator;
	private JTextArea area;
	
	private int[] res;
	
	
	public CalculatorArea(Operation operator) {
		super();
		this.operator = operator;
		operator.addObserver(this);
		area = new JTextArea();
		area.setEditable(false);
	}


	

	public JTextArea getArea() {
		return area;
	}




	@Override
	public void update(Observable o, Object arg) {
			area.setText(null);
			res =operator.getResults();
			if(res.length == 1){
				Integer res1 =  new Integer(res[0]);
			area.insert(res1.toString(), 0);
			} else {
				Integer res2 = new Integer(res[0]);
				Integer res3 = new Integer(res[1]);
				
				area.insert(res2.toString(), 0);
				area.insert("#", area.getCaretPosition());

				area.insert(res3.toString(), area.getCaretPosition());

			}
	}

	
	
}
